
import moment from "moment";
export const MoneyFormat = function(money) {
    if (money && money != null) {
       money = String(money);
       var left = money.split('.')[0], right = money.split('.')[1];
       right = right ? (right.length >= 2 ? '.' + right.substr(0, 2) : '.' + right + '0') : '.00';
       var temp = left.split('').reverse().join('').match(/(\d{1,3})/g);
       return (Number(money) < 0 ? '-' : '') + temp.join(',').split('').reverse().join('') + right;
    } else if (money === 0) { // 注意===在这里的使用，如果传入的money为0,if中会将其判定为boolean类型，故而要另外做===判断
       return '0.00';
    } else {
       return '--';
    }
}

export const nullStr =  function(str) {
    if (!str || str === null || str === '') {
       return '--';
    } else {
		return str;
	}
}

export const hiddenPhone = function(str) {
	if (!str || str === null || str === '') {
	   return '-';
	} else {
		return str.substring(0,3) + "****" + str.substring(7)
	}
}
export const hiddenBank = function(str) {
	if (!str || str === null || str === '') {
	   return '';
	} else {
		return str.slice(0,4) + str.slice(4,-4).replace(/./g,'*') + str.slice(-4)
	}
}
export const hiddenIdcard = function(str) {
	if (!str || str === null || str === '') {
	   return '';
	} else {
		return str.slice(0,6) + str.slice(6,-4).replace(/./g,'*') + str.slice(-4)
	}
}
export const hiddenName =  function(str) {
    if (!str || str === null || str === '') {
       return '';
    } else if(str.length<=2){
		return str.substring(0,1) + str.slice(1).replace(/./g,'*')
	}else{
      return str.slice(0,1) + str.slice(1,-1).replace(/./g,'*') + str.slice(-1)
   }
}
export const dateFormat = function(str) {
    if (!str || str === null || str === '') {
       return '';
    } else {
		return moment(str).format('YYYY-MM-DD')
	}
}
export const returnFloat = function returnFloat(value){
    var value=Math.round(parseFloat(value)*100)/100;
    var xsd=value.toString().split(".");
    if(xsd.length==1){
        value=value.toString()+".00";
		value=value.replace(/(\d)(?=(\d{3})+\.)/g,"$1,")
        return value;
    }
    if(xsd.length>1){
        if(xsd[1].length<2){
            value=value.toString()+"0";
			value=value.replace(/(\d)(?=(\d{3})+\.)/g,"$1,")
        } else {
			value=value.toString()
			value=value.replace(/(\d)(?=(\d{3})+\.)/g,"$1,")
		}
        return value;
    }
}
